-
Notifications
You must be signed in to change notification settings - Fork 7.9k
samples: http_server: Fix warning about integer name #93468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: http_server: Fix warning about integer name #93468
Conversation
char name[MAX_NAME_LEN]; | ||
|
||
snprintk(name, sizeof(name), "ws[%d]", slot); | ||
snprintk(name, sizeof(name), "ws[%d]", slot % (10 * MAX_NAME_LEN)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look right. The idea is to print the slot value here. If the name variable is too small, let's increase the size of it instead, so something like
MAX_NAME_LEN sizeof("ws[xxxx]")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is not right what I have here, but I think what you suggested also won't help, the issue appears to be that the compiler knows that the max integer value is 10 digits, so the max size would theoretically be sizeof("ws[xxxxxxxxxx]")
, is that what you think it should be changed to ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed the same idea as you said but did sizeof("ws[]") + 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this sizeof("ws[xxxxxxxxxx]")
is what I was suggesting, so just adding enough x to silence the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having +10 certainly works, but it is now a magical constant and not immediately obvious why it is there. Therefore we used the "template" way in other part of the code and I suggest we do that here too.
d81befc
to
1e995c6
Compare
When building with CONFIG_DEBUG=y, there is a build warning about the name being truncated due to integer size is larger than MAX_NAME_LEN. So fix MAX_NAME_LEN to be large enough to handle 10 digit integer, which is maximum. Signed-off-by: Declan Snyder <[email protected]>
1e995c6
to
0c58043
Compare
|
|
||
if (IS_ENABLED(CONFIG_THREAD_NAME)) { | ||
#define MAX_NAME_LEN sizeof("ws[xx]") | ||
#define MAX_NAME_LEN (sizeof("ws[xxxxxxxxxx]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@decsny - I don't want to be too nit-picky, so this isn't blocking by any means, but I think MAX_NAME_LEN
should probably be defined in terms of CONFIG_THREAD_MAX_NAME_LEN
. If you can respin, sure, but otherwise, I think we can probably merge anyway.
Below, N
is the minimum expected number of digits to use for slots
#define MAX_NAME_LEN (sizeof("ws[xxxxxxxxxx]")) | |
BUILD_ASSERT(CONFIG_THREAD_MAX_NAME_LEN > (sizeof("ws[]") + N), "CONFIG_THREAD_MAX_NAME_LEN is too small"); | |
#define MAX_NAME_LEN (CONFIG_THREAD_MAX_NAME_LEN - sizeof("ws[]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer to @jukkar who had this opinion for how it is now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we go with what we have now, we have used this pattern in other part of networking code too. If we want to have build asserts, we could introduce that to all places that have the name used.
|
||
if (IS_ENABLED(CONFIG_THREAD_NAME)) { | ||
#define MAX_NAME_LEN sizeof("ws[xx]") | ||
#define MAX_NAME_LEN (sizeof("ws[xxxxxxxxxx]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we go with what we have now, we have used this pattern in other part of networking code too. If we want to have build asserts, we could introduce that to all places that have the name used.
When building with CONFIG_DEBUG=y, there is a build warning about the name being truncated due to integer size is larger than MAX_NAME_LEN. So fix with modulo operator to be clear to the compiler what we expect.